<template>
	<view class="list">
		<appHeader></appHeader>
		<view class="list-main">
			<view class="list-l">
				<view v-for="(item,index) in firstList " :key="item.id" :class="current == item.id? 'active' :''"
					@click="tabsFirst(item.id)">
					{{item.categoryName}}
				</view>
			</view>
			<view class="list-r">
				<scroll-view scroll-y="true" :style="'height:'+swiperHeight + 'px'">
					<view class="r-img">
						<image src="../../static/banner.d093dd6e.png" mode=""></image>
					</view>
					<view class="r-main">
						<view v-for="(item,index) in secondList" :key="index" class='r-main-item'>
							<image :src="item.thumbnail " mode=""></image>
							<text>{{item.categoryName}}</text>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getFirstCategorys,
		getSecondCategorys
	} from '@/api/course.js'
	import appHeader from '@/components/commom/appHeader.vue'
	import {
		mixin
	} from '@/mixins/mixin.js'
	export default {
		mixins: [mixin],
		components: {
			appHeader
		},
		data() {
			return {
				firstList: [{
					id: -1,
					categoryName: '全部'
				}],
				secondList: [],
				current: -1,
				categorysParams: {
					categoryId: -1
				},
				swiperHeight:1000
			}
		},
		onLoad() {
			// 获取一级类
			getFirstCategorys().then(data => {
				this.firstList = [...this.firstList, ...data.list]
			})
			this.getCategorys()
		},
		methods: {
			// 获取二级类
			getCategorys() {
				getSecondCategorys(this.categorysParams).then(data => {
					this.secondList = data.list
				})
			},
			// 切换一级类
			tabsFirst(index) {
				this.current = index
				this.categorysParams.categoryId = index
				this.getCategorys()
			}
		},
		onReady() {
			this.swiperHeight = this.getHeight('.header-search');
		}
	}
</script>

<style>
	.list-main {
		display: flex;
		justify-content: space-between;
	}

	.list-l {
		width: 217rpx;
		line-height: 77rpx;
		font-size: 28rpx;
		color: #777777;
		text-align: center;
		background: rgba(247, 249, 255, 0.39);
	}
	.list-l >view{
		padding: 18rpx 0;
	}
	.list-r {
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.r-img {
		padding: 0 34rpx;
	}

	.r-img image {
		width: 479rpx;
		;
		height: 192rpx;
		border-radius: 17rpx;
	}

	.r-main {
		display: flex;
		flex-wrap: wrap;
	}

	.r-main-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 33.33333%;
		margin-top: 44rpx;
	}

	.r-main-item image {
		width: 83rpx;
		height: 83rpx;
	}

	.r-main-item text {
		font-size: 24rpx;
		color: #A9A9A9;
		padding: 18rpx 0;
	}

	.active {
		position: relative;
		color: #3780ef;
		font-weight: 400;
	}

	.active:before {
		content: '';
		position: absolute;
		left: 0;
		top: 50%;
		transform: translateY(-50%);
		width: 6rpx;
		height: 40%;
		background: #3780ef;
		border: 1px solid #3780ef;
		border-radius: 3px;
	}
</style>